/* 选择环境 */
const inquirer = require('inquirer')
const { resolve, exit } = require('./index')

module.exports = function(selectMsg) {
  try {
    /*
      格式
      [
        { name: '测试环境', value: 'test' },
        { name: '生产环境', value: 'production' },
      ]
    */
    const { envs } = require(resolve('micro-config'))

    return inquirer.prompt([{
      type: 'list',
      name: 'env',
      message: selectMsg,
      choices: envs
    }])
  } catch (err) {
    exit(err)
  }
}
